package com.changgou.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.changgou.framework.entity.PageResult;
import com.changgou.goods.dao.TemplateDao;
import com.changgou.goods.service.TemplateService;
import com.haha.goods.entity.Template;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author Yang
 * @date 2020/11/7
 */
@Service
public class TemplateServiceImpl extends ServiceImpl<TemplateDao, Template> implements TemplateService {
    @Override
    public PageResult findPage(Template template, int page, int size) {
        QueryWrapper<Template> queryWrapper = new QueryWrapper<>();
        if (!ObjectUtils.isEmpty(template)){
            queryWrapper.eq(template.getId()!=null,"id",template.getId());
            queryWrapper.like(!StringUtils.isEmpty(template.getName()),"name",template.getName());
            // 规格数量
            queryWrapper.eq(template.getParaNum()!=null,"para_num",template.getParaNum());
            // 参数数量
            queryWrapper.eq(template.getSpecNum()!=null,"spec_num",template.getSpecNum());
        }
        Integer count = baseMapper.selectCount(queryWrapper);
        int offset = (page-1)*size;
        List<Template> templates = baseMapper.findPage(queryWrapper,offset,size);
        return null;
    }

    @Override
    public Template findByCategoryId(Integer id) {
        return baseMapper.findByCategoryId(id);
    }
}
